package com.hrm.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.hrm.pojo.Rewards;
import com.hrm.pojo.Working;
import com.hrm.service.RewardService;
import com.hrm.service.WordingService;


@Namespace("/rewards")
public class jiangfaAction {

	private List<Rewards> rewardlist;
	private RewardService rewardService;
	private String workName;
	private String id;
	private Rewards rewards;
	private List<Working> wlist;
	private WordingService workingService;
	/*
	 * 
	 * 找到所有的奖罚人员，跳转到页面显示
	 */
	@Action(value="showAll",results={@Result(name="success",type="dispatcher",location="showAll.jsp")})
	public String showAll(){
		rewardlist = rewardService.findAll();
		return "success";
	}
	
	
	@Action(value="add",results={@Result(name="success",type="dispatcher",location="add.jsp")})
	public String add(){
		wlist = workingService.findAll();
		return "success";
	}
	
	
	public String save(){
		Working w = workingService.findName(workName);
		rewards.setWorker(w);
		rewardService.save(rewards);
		return "success";
	}

	/**
	 * 删除一个奖罚人员
	 * @return
	 */
	@Action(value="del",results={@Result(name="success",type="redirectAction",params={"actionName","showAll","namespace","/rewards"})})
	public String del(){
		rewardService.del(id);
		return "success";
	}
	

	//跳转去编辑的页面
	@Action(value="edit",results={@Result(name="success",type="dispatcher",location="edit.jsp")})
	public String toedit(){
		rewards = rewardService.findById(id);
		
		return "success";
	}
		
	
	@Action(value="update",results={@Result(name="success",type="redirectAction",params={"actionName","showAll","namespace","/rewards"})})
	public String update(){
		Working w = workingService.findName(workName);
		rewards.setWorker(w);
		rewardService.save(rewards);
		return "success";
	}
	//get set 
	public List<Rewards> getRewardlist() {
		return rewardlist;
	}


	public void setRewardlist(List<Rewards> rewardlist) {
		this.rewardlist = rewardlist;
	}

	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}

	

	public Rewards getRewards() {
		return rewards;
	}

	public void setRewards(Rewards rewards) {
		this.rewards = rewards;
	}
	

	public String getWorkName() {
		return workName;
	}

	public void setWorkName(String workName) {
		this.workName = workName;
	}

	
	
	public List<Working> getWlist() {
		return wlist;
	}


	public void setWlist(List<Working> wlist) {
		this.wlist = wlist;
	}


	@Autowired
	public void setRewardService(RewardService rewardService) {
		this.rewardService = rewardService;
	}

	@Autowired
	public void setWorkingService(WordingService workingService) {
		this.workingService = workingService;
	}
	
	
	
}
